﻿using System;

namespace SLS.ExClassLib.MultiThreading.Extensions
{
    public static class DisposableExtensions
    {
        public static void SafeDispose(this IDisposable disposable, Action<Exception> exceptionHandler)
        {
            if (disposable == null)
                return;

            try
            {
                disposable.Dispose();
            }
            catch (Exception exp)
            {
                if (exceptionHandler != null)
                    exceptionHandler(exp);
            }
        }

        public static void SafeDispose(this IDisposable disposable)
        {
            SafeDispose(disposable, null);
        }
    }
}